package org.academy.funfair;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FunfairProperties {

	private static final Logger logger = LoggerFactory.getLogger(FunfairProperties.class);
	private static Properties prop = new Properties();
	private static String appName;

	static {
		loadConfiguration();
	}

	public static String getName() {
		return prop.getProperty("app.name");
	}

	public static String getProfile() {
		return prop.getProperty("app.profile");
	}

	public static String getVersion() {
		return prop.getProperty("app.version");
	}

	private static void loadConfiguration() {
		try (InputStream in = FunfairProperties.class.getResourceAsStream("/funfair.properties")) {
			prop.load(in);

			appName = prop.getProperty("app.name", "funfair").replaceAll("[/\\\\]", "");
			logger.debug("Funfair loadConfiguration: [app.name={}, appName={}]", prop.getProperty("app.name"), appName);
		} catch (IOException e) {
			logger.error("", e);
		}
	}

}
